<template>
	<div style="margin-right: 30px">
		<el-form ref="formObj" :model="wyform"  label-width="100px">
			<el-form-item label="权限名称" prop="name">
				<el-input placeholder="请输入权限名称" v-model="wyform.name"></el-input>
			</el-form-item>
			
			<el-form-item label="菜单路径" prop="path">
				<el-input placeholder="请输入菜单路径" v-model="wyform.path"></el-input>
			</el-form-item>
			<el-form-item label="类别" prop="type">
			    <el-radio-group v-model="wyform.type">
			    <el-radio :value="1">目录</el-radio>
			    <el-radio :value="0">按钮</el-radio>
			    </el-radio-group>
			</el-form-item>
			<el-form-item label="说明" prop="description">
				<el-input type="textarea" :rows="5" placeholder="请输入说明" v-model="wyform.description"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" plain :icon="Save" @click="save">保存</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script setup>
import Save from '@/components/icons/save.vue'
import { ref,reactive } from 'vue'
import { get,post } from '@/plugins/axios'
import { _axios } from '@/plugins/axios';
import url from './util'
const emits = defineEmits(['update:show','getTableData'])

const props = defineProps(['id','level','parentId'])



const formObj = ref()
const wyform = reactive({
  id: null,
  name: '',
  description: '',
  path: '',
  level: null,
  parentId: null,
  type: null
})

function save(){
	post(props.id ? url.update : url.add,wyform,content =>{
		emits('update:show',false)
		emits('getTableData')
	},formObj)
}	
function getById(){
	get(url.getById,{ id:props.id },content => {
		for(const key in wyform){
			if(Object.prototype.hasOwnProperty.call(content,key) ) 
			{
				wyform[key] = content[key]
			}
		}
		console.dir(wyform)
	})
}
if(props.id){
	wyform.id = props.id
	getById()

}else{
	wyform.level = props.level
	wyform.parentId = props.parentId
}



</script>

<style>
</style>